<template>
  <div class="box">
    <div style="width: 95%; height: 100%; margin: 0 auto" class="box-content">
      <!-- 头部 -->
      <div class="box-top" style="display: flex">
        <div style="width: 40%" class="box-top-left">
          <div class="daohang">
            <i style="font-size: 20px; color: #999; line-height: 60px; float: left" class="el-icon-s-home"></i>
            <el-breadcrumb>
              <el-breadcrumb-item style="font-size: 15px; color: #999; line-height: 60px; margin-left: 8px; display: block; float: left">首页 </el-breadcrumb-item>
              <i style="font-size: 15px; line-height: 63px; margin-left: -3px; float: left" class="el-icon-folder-opened"></i>
              <el-breadcrumb-item style="font-size: 15px; line-height: 64px; margin-left: 8px; display: block; float: left">财务管理</el-breadcrumb-item>
              <i style="font-size: 15px; line-height: 63px; margin-left: 5px; float: left" class="el-icon-folder-opened"></i>
              <el-breadcrumb-item style="font-size: 15px; line-height: 64px; margin-left: 8px; display: block; float: left">优惠管理</el-breadcrumb-item>
            </el-breadcrumb>
          </div>
        </div>
      </div>
      <!--内容 -->

      <div class="middle">
        <div class="choice" style="display: flex; align-items: center">
          <a style="margin-left: 35px; border-radius: 5px; width: 80px; height: 34px; display: block; line-height: 34px" @click="curId = 0" :class="{ cur: curId === 0 }">
            <span style="font-size: 15px; display: block; text-align: center">优惠卷明细</span></a
          >
          <a
            style="font-size: 15px; border-radius: 5px; width: 80px; height: 34px; margin-left: 20px; line-height: 34px; width: 100px; display: block"
            @click="curId = 1"
            :class="{ cur: curId === 1 }"
          >
            <span style="font-size: 15px; display: block; text-align: center">发送记录</span></a
          >
          <a
            style="font-size: 15px; border-radius: 5px; width: 80px; height: 34px; margin-left: 20px; line-height: 34px; width: 100px; display: block"
            @click="curId = 2"
            :class="{ cur: curId === 2 }"
          >
            <span style="font-size: 15px; display: block; text-align: center">优惠卷分类</span></a
          >
        </div>
        <div class="Discount2" v-show="curId === 0">
          <div class="Discount-box">
            <button @click="addcoupon" style="width: 90px; height: 27px; background: white; border: 1px solid #999; margin-left: 35px; margin-top: 40px">添加新优惠卷</button>

            <div class="table-box" style="margin-top: 40px">
              <el-table :data="disList" height="242" border style="width: 90%; margin-left: 2%">
                <el-table-column class="table" cell-style="background:red" prop="id" label="优惠卷ID" width="180"> </el-table-column>
                <el-table-column prop="discont" label="发放时间"> </el-table-column>
                <el-table-column prop="outtime" label="结束时间"> </el-table-column>
                <el-table-column prop="quantity" label="发放数量"> </el-table-column>
                <el-table-column prop="condition" label="使用条件"> </el-table-column>
                <el-table-column prop="project" label="优惠项目"> </el-table-column>
                <el-table-column prop="surplus" label="剩余数量"> </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
        <div class="Discount2" v-show="curId === 1">
          <div class="Discount-box">
            <div style="width: 100%; height: 40px"></div>
            <div class="table-box" style="margin-top: 40px">
              <el-table :data="disList" height="242" border style="width: 90%; margin-left: 2%">
                <el-table-column class="table" cell-style="background:red" prop="id" label="优惠卷ID" width="180"> </el-table-column>
                <el-table-column prop="discont" label="发放时间"> </el-table-column>
                <el-table-column prop="outtime" label="结束时间"> </el-table-column>
                <el-table-column prop="quantity" label="发放数量"> </el-table-column>
                <el-table-column prop="condition" label="使用条件"> </el-table-column>
                <el-table-column prop="project" label="优惠项目"> </el-table-column>
                <el-table-column prop="surplus" label="剩余数量"> </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
        <div class="Discount2" v-show="curId === 2">
          <div class="Discount-box">
            <button @click="cancel()" style="width: 90px; height: 27px; background: white; border: 1px solid #999; margin-left: 35px; margin-top: 40px">添加优惠卷分类</button>
            <div class="table-box" style="margin-top: 40px; margin-left: 40px">
              <el-table :data="disList1" height="290" border style="width: 30%; margin-left: 2%; z-index: 1">
                <el-table-column class="table" cell-style="background:red" prop="id" label="ID" width="180"> </el-table-column>
                <el-table-column prop="title" label="标题"> </el-table-column>
                <el-table-column label="操作">
                  <template v-slot="{ row }">
                    <div style="width: 100%; display: flex; justify-content: space-evenly">
                      <i @click="cancel2(row)" style="font-size: 18px" class="el-icon-edit"></i>
                      <i @click="del(row)" style="font-size: 18px" class="el-icon-delete"></i>
                    </div>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
        <div class="Discount2" v-show="curId === 3">444</div>
      </div>
      <div v-if="isShow1" class="popContainer">
        <div class="popContainer-box1" style="position: relative">
          <div style="width: 100%; height: 40px; background: #bbbbbb; display: flex; justify-content: space-between" class="popContainer-box-top">
            <span style="font-size: 14px; display: block; margin-left: 20px; margin-top: 10px">添加分类</span>
            <span @click="cancel1()" style="font-size: 20px; display: block; margin-right: 20px; margin-top: 8px">❌</span>
          </div>
          <div style="margin-top: 120px; margin-left: 110px; font-weight: 700">
            分类名称<input v-model="value" style="margin-left: 30px; width: 140px; height: 25px" placeholder="请输入分类名称" type="text" />
          </div>
          <div style="margin-top: 110px; margin-left: 165px; font-weight: 700">
            <button @click="queding()" style="width: 65px; height: 25px; background: #1694f0; border: none; color: white">确定</button>
            <button @click="clear()" style="margin-left: 25px; width: 65px; height: 25px; background: #1694f0; border: none; color: white">取消</button>
          </div>
        </div>
      </div>
      <div v-if="isShow2" class="popContainer">
        <div class="popContainer-box1" style="position: relative">
          <div style="width: 100%; height: 40px; background: #bbbbbb; display: flex; justify-content: space-between" class="popContainer-box-top">
            <span style="font-size: 14px; display: block; margin-left: 20px; margin-top: 10px">编辑分类</span>
            <span @click="cance2()" style="font-size: 20px; display: block; margin-right: 20px; margin-top: 8px">❌</span>
          </div>
          <div style="margin-top: 120px; margin-left: 110px; font-weight: 700">
            分类名称<input v-model="value" style="margin-left: 30px; width: 140px; height: 25px" placeholder="请输入分类名称" type="text" />
          </div>
          <div style="margin-top: 110px; margin-left: 165px; font-weight: 700">
            <button @click="queding1(distitle)" style="width: 65px; height: 25px; background: #1694f0; border: none; color: white">确定</button>
            <button @click="clear()" style="margin-left: 25px; width: 65px; height: 25px; background: #1694f0; border: none; color: white">取消</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.box {
  width: 100%;
  height: 900px;
  // 头部
  .box-top {
    width: 100%;
    // background:blue;
    // 导航
    .daohang {
      width: 100%;
      height: 50px;
    }
  }
  .middle {
    width: 100%;
    height: 500px;

    .choice {
      width: 100%;
      height: 50px;
      border: 2px solid #f0f0f0;
      .cur {
        background: #ff9800;
        color: #fff;
        width: 100px;
      }
    }
    .Discount-box {
      width: 100%;
      height: 500px;
    }
  }
}

.popContainer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 3;
  .popContainer-box {
    width: 50%;
    background: white;
    height: 600px;
    margin-left: 15%;
    margin-top: 13%;
  }
  .popContainer-box1 {
    width: 40%;
    background: white;
    height: 500px;
    margin-left: 22%;
    margin-top: 14%;
  }
}
.reg {
  width: 500px;
  height: 40px;
  margin: 20px 55px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.checkColor {
  width: 55px;
  color: white;
  height: 25px;
  background: red;
  border: none;
  border-radius: 5px;
}
.checkColor1 {
  width: 55px;
  color: white;
  height: 25px;
  background: #46b2f7;
  border: none;
  border-radius: 5px;
}
.Recharge {
  width: 68%;
  height: 400px;
  margin-top: 15px;
  border-top: 5px solid #f6f8f9;
}
</style>

<script>
import { getDis, getPre, addPre, upPer, delPre } from '../../api/index'
export default {
  data() {
    return {
      curId: 0,
      disList: [],
      disList1: [],
      isShow1: false,
      value: '',
      isShow2: false,
      distitle: [],
    }
  },
  methods: {
    cancel() {
      this.isShow1 = true
    },
    cancel1() {
      this.isShow1 = false
    },
    cance2() {
      this.isShow2 = false
    },
    cancel2(row) {
      this.distitle = row
      this.isShow2 = true
    },
    getDisList() {
      getDis().then((res) => {
        this.disList = res.data
      })
    },
    addcoupon() {
      this.$router.push('/sale_Discount/add')
    },
    getPreList() {
      getPre().then((res) => {
        this.disList1 = res.data
      })
    },
    queding() {
      let a = {
        title: this.value,
      }
      if (this.value !== '') {
        addPre(a).then((res) => {
          this.isShow1 = false
          this.getPreList()
        })
      }
    },

    clear() {
      this.value = ''
    },
    queding1(distitle) {
      this.isShow2 = false
      upPer({ title: this.value, id: distitle.id }).then((res) => {
        this.getPreList()
      })
    },
    del(row) {
      delPre({ id: row.id }).then((res) => {
        this.getPreList()
      })
    },
  },
  created() {
    this.getDisList()
    this.getPreList()
  },
}
</script>
